<template>
  <div>
    <h3>Supermatic-UI/Supermatic-UI</h3>
    <p>一个用于创建低代码和无代码应用的项目。</p>

    <!-- 可视化设计器 -->
    <div class="designer-section">
      <h4>可视化设计器</h4>
      <div class="design-area">
        <draggable v-model="components" @end="onDragEnd" item-key="name">
          <template #item="{ element }">
            <div class="component-item">
              {{ element.name }}
            </div>
          </template>
        </draggable>
      </div>
    </div>

    <!-- 导出功能 -->
    <div class="export-section">
      <h4>导出功能</h4>
      <button @click="exportDesign">导出设计</button>
      <pre v-if="exportedData">{{ exportedData }}</pre>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import draggable from 'vuedraggable';

// 模拟组件数据
const components = ref([
  { name: '表单' },
  { name: '按钮' },
  { name: '表格' }
]);

// 模拟导出数据
const exportedData = ref(null);

// 导出设计
const exportDesign = () => {
  exportedData.value = JSON.stringify(components.value, null, 2);
};

// 拖拽结束时的处理函数
const onDragEnd = () => {
  console.log('拖拽结束');
};
</script>

<style scoped>
.designer-section,
.export-section {
  margin-bottom: 20px;
}

.design-area {
  border: 1px solid #ccc;
  padding: 10px;
  min-height: 100px;
}

.component-item {
  background-color: #f0f0f0;
  margin: 5px 0;
  padding: 5px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

button {
  padding: 5px 10px;
  cursor: pointer;
}

pre {
  background-color: #f9f9f9;
  padding: 10px;
  border: 1px solid #ddd;
  white-space: pre-wrap;
}
</style>